#ifndef __SINGLECUT_H__
#define __SINGLECUT_H__

#include "WordSegmentation.h"
#include <mutex>


class SingleCut {
public:
    static WordSegmentation *getInstance() {
        if(_wordSeg == nullptr) {
            std::lock_guard<std::mutex> lock(_mutex);
            if(_wordSeg == nullptr) {
                _wordSeg = new WordSegmentation();
                atexit(destory);
            }
        }
        return _wordSeg;
    }

    static void destory() {
        if(_wordSeg) {
            delete _wordSeg;
            _wordSeg = nullptr;
        }
    }

private:
    SingleCut() {}
    ~SingleCut() {}
    SingleCut(const SingleCut &) = delete;
    SingleCut operator=(const SingleCut&) = delete; 

private:
    static WordSegmentation *_wordSeg;
    static std::mutex _mutex;
};


#endif

